package com.lanqiao.gxnushop.mapper;

import com.lanqiao.gxnushop.entity.Buyers;
import io.swagger.v3.oas.annotations.media.Schema;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

@Schema(description ="买家表")
@Mapper
public interface BuyersMapper {
    @Schema(description ="添加买家")
    @Insert("insert into buyers(buyerId,name,email,phone,zcsj) values (#{buyerId},#{name},#{email},#{phone},now())")
    boolean add(Buyers buyers);

    /**注册时同步 将主键 插入 buyers 表*/
    @Insert("insert into buyers(buyerId,zcsj) values(#{buyerId},now())")
    boolean addBuyer(String buyerId);

    @Schema(description ="删除买家")
    @Delete("delete from buyers where buyerId=#{buyerId}")
    boolean delete(String buyerId);

    @Schema(description ="更新买家")
    @Update("update buyers set name=#{name},email=#{email},phone=#{phone} where buyerId=#{buyerId}")
    boolean update(Buyers buyers);

    @Schema(description ="根据买家id查询买家")
    @Select("select * from buyers where buyerId=#{buyerId}")
    Buyers findById(String buyerId);

    @Schema(description ="查询所有买家")
    @Select("select * from buyers")
    ArrayList<Buyers> list();

    @Schema(description ="根据名字模糊查询买家")
    @Select("select * from buyers where name like '%${name}%'")
    ArrayList<Buyers> findByName(String name);

    @Update("update buyers set yhtx=#{yhtx} where buyerId=#{buyerId}")
    boolean updateYhtx(Buyers buyers);
}
